package com.javabi.htmlbuilder.html.element.head;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElement;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * An HTML Title Element.
 * <p>
 * &lt;title&gt; ... &lt;/title&gt;
 * </p>
 */
public class Title extends HTMLElement<Title> {

	/** The title. */
	private String title = null;

	/**
	 * Creates a new title.
	 */
	public Title() {
	}

	/**
	 * Creates a new title.
	 * @param title the title.
	 */
	public Title(String title) {
		this.title = title;
	}

	/**
	 * Returns the title
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Sets the title
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Returns true to format this element.
	 * @return true to format this element.
	 */
	public boolean format() {
		return title != null && title.indexOf('\n') != -1;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.TITLE;
	}

	/**
	 * Append this to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendTo(HTMLBuilder html) {
		if (title != null) {
			html.element(this, title);
		}
		return html;
	}
}
